package cn.summit.realm;

import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.util.ByteSource;

/**
 * @author summit
 * @since 2020/12/18 22:11
 */
public class MyRealm extends AuthorizingRealm {

    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
        return null;
    }

    /**
     * @param token
     * @return
     * @throws AuthenticationException
     * @see org.apache.shiro.realm.SimpleAccountRealm#doGetAuthenticationInfo
     */
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
        throws AuthenticationException {
        UsernamePasswordToken upToken = (UsernamePasswordToken) token;
        String username = upToken.getUsername();

        if (username.equals("summit")) {
            SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(username, "123456",

                this.getName());
            return info;
        }
        return null;
    }
}
